using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;

public class BossControl : MonoBehaviour
{
    public static BossControl Instance;
    private Animator ani;
    private float timer = 0;
    public float distance = 0.03f;
    void Awake()
    {
        Instance = this;
        ani = GetComponent<Animator>();
    }

    void Update()
    {
        timer -= Time.deltaTime;
        if(timer < 0){
            ani.SetBool("isUp",false);
        }
        if(transform.position.y < 0){
            if (playerControl.Instance != null) playerControl.Instance.ani.SetBool("die", true);
        }
        if(transform.position.y > 0.47f){
            ani.SetBool("die",true);
            if (EnemyPoint.Instance != null) EnemyPoint.Instance.isTimerActive = false;
            if (EnemyPoint1.Instance != null) EnemyPoint1.Instance.isTimerActive = false;
            if (EnemyControl.Instance != null) EnemyControl.Instance.isFly = false;
            if (EnemyControl1.Instance != null) EnemyControl1.Instance.isFly = false;
        }
    }

    private void OnTriggerEnter2D(Collider2D collider) {
        if(collider.tag == "Bullet"){
            Destroy(collider.gameObject);
            ani.SetBool("isUp",true);
            timer = 1;

        }
    }

    void up()
    {
        var range = transform.position;
        range.y += distance;
        transform.position = range;
    }

    void down()
    {
        var range = transform.position;
        range.y -= distance;
        transform.position = range;
    }
}
